using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using StupidSpaceThing;

namespace RacerGame
{
	internal class FlyingEntity : Entity
	{		
		protected Vector2 force;
		public bool DoRotateToAngle = false;
		public Map.Cell OccupiedCell;

		public void ApplyForce(Vector2 force) {
			if( ColObject != null ) {
				colObject.Body.ApplyForce(force);
			} else {
				this.force = force / 100.0f;
			}
		}

		public FlyingEntity(Model model) : this(model, new Vector3(0, 0, 0), Quaternion.Identity, 1.0f) { }
		public FlyingEntity(Model model, Vector3 position) : this(model, position, Quaternion.Identity, 1.0f) { }
		public FlyingEntity(Model model, Vector3 position, Quaternion rotation) : this(model, position, rotation, 1.0f) { }
		public FlyingEntity(Model model, Vector3 position, Quaternion rotation, float scale)
			: base(model, position, rotation, scale) {

		}

		public virtual void Update(RealGameTime gameTime) {
			if( ColObject != null ) {
				colObject.UpdateEntityPosition();
			} else {
				Position += new Vector3(force.X, 0, force.Y);
				UpdatePositionMatrix();
				if( DoRotateToAngle ){
					RotateTowards(Position + new Vector3(force.X, 0, force.Y));					
				}				
			}
		}

		public override void Die() {
			if( OccupiedCell != null ) {
				OccupiedCell.Occupier = null;
			}
			base.Die();
		}
	}
}
